﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Script.Serialization;
using Wjtour.BLL;
using Wjtour.Common;

namespace Wjtour.Web.Admin.Ajax
{
    public class GetHotelHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            Wjtour.BLL.hotel_bll _sbll = new hotel_bll();
            var hotels = _sbll.GetAll<Wjtour.Domain.hotel>("select * from hotel");
            List<LableValuePair> pairs = new List<LableValuePair>();
            pairs.Add(new LableValuePair
            {
                label = "请选择...",
                value = "0"
            });
            foreach (var item in hotels)
            {
                pairs.Add(new LableValuePair
                {
                    label = item.hotelname + "[" + item.address + "]",
                    value = item.id.ToString()
                });
            }
            if (pairs.Count > 0)
            {
                StringBuilder output = new StringBuilder();
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                serializer.Serialize(pairs, output);
                context.Response.ContentType = "text/json";
                context.Response.Write(output.ToString());
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
